package leetCode;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class t438 {
    public static void main(String[] args) {
        new Solution438().findAnagrams("cbaebabacd","abc");
    }
}
class Solution438 {
    public List<Integer> findAnagrams(String s, String p) {
        List<Integer> ret=new ArrayList<>();
        char pSort[]=p.toCharArray();
        Arrays.sort(pSort);
        String pSortString=new String(pSort);
        int pLength= p.length();
        for (int i=0;i+pLength<=s.length();i++){
            String windowsString=s.substring(i,i+pLength);
            char windowsChar[]=windowsString.toCharArray();
            Arrays.sort(windowsChar);
            String windowsStringSort=new String(windowsChar);
            if (windowsStringSort.equals(pSortString)){
                ret.add(i);
            }
        }
        return ret;
    }
}